package com.huangxt.test.modify.info;

import com.huangxt.test.StringCommonUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class ModifySupportInfo implements ModifyInfoInterface {
    @Override
    public void insertModifyInfo(Object old, Object newly) throws Exception {
        if(!(old instanceof Support)||!(newly instanceof Support)){
            throw new Exception("类型异常");
        }
        Arrays.asList(ModifyInfoEnumForSupport.values()).forEach(action->{
            try {
                Method method = Support.class.getMethod("get"+action.getNode());
                String oldInfo = StringCommonUtil.checkNull(method.invoke(old));
                Object newInfo = StringCommonUtil.checkNull(method.invoke(newly));
                if(!oldInfo.equals(newInfo)){
                    System.out.println(action.getDesc()+"字段变更from:"+oldInfo+"to:"+newInfo);
                }
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        });
    }
}
